package com.qifenqian.turbot.module.adapter.order

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.qifenqian.turbot.R
import com.qifenqian.turbot.module.entity.response.order.OrderDetailEntity
import kotlinx.android.synthetic.main.item_order_detail_dish.view.*

/**
 * @author H
 * @createTime 2019/1/11 08:54
 * @description
 * @see
 * @since
 */
class OrderDetailAdapter(data: List<OrderDetailEntity.OrderDishDetail>) : BaseQuickAdapter<OrderDetailEntity.OrderDishDetail, BaseViewHolder>(R.layout.item_order_detail_dish, data) {

    override fun convert(helper: BaseViewHolder, item: OrderDetailEntity.OrderDishDetail) {
        val view = helper.itemView
        view.tv_item_order_detail_name.text = item.name
        view.tv_item_order_detail_count.text = "*${item.count}"
        view.tv_item_order_detail_price.text = "${item.price / 100}元"
    }

    fun removeData(someData: Collection<OrderDetailEntity.OrderDishDetail>) {
        mData.removeAll(someData)
        notifyItemRangeRemoved(mData.size + headerLayoutCount, someData.size)
        val dataSize = if (mData == null) 0 else mData.size
        if (dataSize == someData.size) {
            notifyDataSetChanged()
        }
    }
}
